<template>
    <!-- 岗位变更日志 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <!-- 表格 -->
            <list-table
                    ref="table"
                    :page-keys="['pageNum', 'pageSize', 'total']"
                    :columns="columns"
                    :request="loadData"
                    :start-index="0">
                <template slot="businessType" slot-scope="text, record">
                    <span v-if="record.businessType == 1">系统变更</span>
                    <span v-else-if="record.businessType == 2">项目人员调用</span>
                    <span v-else-if="record.businessType == 3">项目立项</span>
                </template>
                <template slot="changeType" slot-scope="text, record">
                    <span v-if="record.changeType == 1">新增</span>
                    <span v-else-if="record.changeType == 2">移除</span>
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
  import { getPostsChangeList } from '@/api/system/postsChangeLog' // api
  import BasePage from '@/views/basePage' // 基础配置
  import moment from 'moment'
  import { postChangeLog } from '@/mixin/mixin'

  const searchArr = [
    // 搜索框
    {
      name: '人员名称',
      value: 'userName',
      type: 'input',
    },
    {
      name: '发起业务',
      value: 'businessType',
      type: 'select',
      data: [
        {
          value: '1',
          label: '系统变更'
        },
        {
          value: '2',
          label: '项目人员调用'
        },
        {
          value: '3',
          label: '项目立项'
        }
      ]
    },
    {
      name: '变更类型',
      value: 'changeType',
      type: 'select',
      data: [
        {
          value: '1',
          label: '新增'
        },
        {
          value: '2',
          label: '移除'
        }
      ]
    },
    {
      name: '对应岗位',
      value: 'changePostName',
      type: 'input',
    },
    {
      name: '创建时间阶段',
      type: 'dateRange',
      value: 'meetTimeRange',
      attr: {
        rangeFormat: ['startTime', 'endTime'],
      },
    },
  ]
  const columns = [
    {
      title: '序号',
      width: 80,
      dataIndex: 'index',
      customRender() {
        return arguments[2] + 1
      },
    },
    {
      title: '人员名称',
      dataIndex: 'userName',
      ellipsis: true,
    },
    {
      title: '发起业务',
      dataIndex: 'businessType',
      scopedSlots: { customRender: 'businessType' },
      ellipsis: true,
    },
    {
      title: '类型',
      dataIndex: 'changeType',
      scopedSlots: { customRender: 'changeType' },
      ellipsis: true,
    },
    {
      title: '对应岗位',
      dataIndex: 'changePostName',
      ellipsis: true,
    },
    {
      title: '当前拥有的岗位',
      dataIndex: 'currentPost',
      ellipsis: true,
    },
    {
      title: '当前拥有的角色',
      dataIndex: 'currentRole',
      ellipsis: true,
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
    },
  ]
  export default {
    name:'a'+Date.now(),
    mixins: [postChangeLog],
    data() {
      this.columns = columns
      this.searchArr = searchArr
      return {
        queryParam: {}, // 查询参数
        loadData: (parameter) => {
          if(this.queryParam.startTime){
            this.queryParam.startTime = moment(this.queryParam.startTime).format('YYYY-MM-DD') + ' 00:00:00'
            this.queryParam.endTime = moment(this.queryParam.endTime).format('YYYY-MM-DD') + ' 23:59:59'
          }
          const requestParameters = Object.assign({}, parameter, { param: this.queryParam })
          return getPostsChangeList(requestParameters).then((res) => {
            if (res.code === '0') {
              let data = res.data?.list.map(item =>{
                item.createTime = moment(item.createTime).format('YYYY-MM-DD')
                return item
              })
              return { code: 200, data: data, total: res.data?.total }
            }
          })
        },
      }
    },
    created(){
      /**
       * 获取一周内岗位变更数量
       */
      this.handleGetPostsChangeLog()
    },
    methods: {
      // 搜索
      search(value) {
        value && (this.queryParam = value)
        this.$refs.table.refresh(true)
      },
    },
  }
</script>

<style lang="less" scoped>
    .alert_text {
        color: rgb(216, 135, 15);
    }
</style>
